class ListNode {
    int val;
    ListNode next;
    ListNode() {}
     ListNode(int val) { this.val = val; }
    ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}
public class Solution {
    public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
        ListNode cur1 = list1;
        ListNode cur2 = list2;
        ListNode newHead = new ListNode();//NewHead为带头结点
        ListNode curN = newHead;
        while(cur1 != null && cur2 != null) {
            if(cur1.val < cur2.val) {
                curN.next = cur1;
                cur1 = cur1.next;
            } else {
                curN.next = cur2;
                cur2 = cur2.next;
            }
            curN = curN.next;
        }
        if(cur1 == null && cur2 != null) {
            curN.next = cur2;
        }else if(cur1 != null && cur2 == null) {
            curN.next = cur1;
        }
        return newHead.next;
    }
}